﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using SharpCommon.Data;
using SharpCommon.Data.MySQL;
using SharpCommon.Logging.Targets;

namespace SharpCommon.ORM.Tool
{
    public partial class fmLogin : Form
    {
        public fmLogin()
        {
            InitializeComponent();

            TestConnection();
        }

        private void TestConnection()
        {
            //首先要构造MySql的连接字符串

            //就不使用mysqlconnectionstringbuilder了

            string connetionString = "database=test;server=127.0.0.1;user id=root;charset=utf8;";

            //DataBaseContext.DBInstance.
            MySqlConnectionStringBuilder connectionString = new MySqlConnectionStringBuilder();
            connectionString.Server = "127.0.0.1";
            connectionString.Database = "test";
            connectionString.CharacterSet = "utf8";

            MySQLHelper mySqlHelper = new MySQLHelper(connetionString.ToString());

            string sql = "show databases;";
            IDataReader dataReader = mySqlHelper.ExecuteReader(sql);
            while (dataReader.Read())
            {
                Trace.WriteLine(dataReader.GetString(0));
            }

            //using (MySqlConnection connection = new MySqlConnection(connetionString.ToString()))
            //{
            //    connection.Open();

            //    string sql = "show databases;";
            //    MySqlCommand command = connection.CreateCommand();
            //    command.CommandText = sql;
            //    MySqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);

            //    while (dataReader.Read())
            //    {
            //        //Trace.Write(dataReader[0].ToString());
            //        Trace.WriteLine(dataReader.GetString(0));
            //    }
            //    dataReader.Close();
            //    connection.Open();
            //    sql = "SHOW TABLES FROM test;";
            //    command.CommandText = sql;
            //    dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);
            //    while (dataReader.Read())
            //    {
            //        Trace.WriteLine(dataReader.GetString(0));
            //    }
            //}
        }
    }
}
